#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int>q;
        for (auto e : stones) q.push(e);
        while (q.size() > 1)
        {
            int a = q.top(); q.pop();
            int b = q.top(); q.pop();
            if (a > b) q.push(a - b);
        }
        return q.size() ? q.top() : 0;
    }
};